package cn.kgc.api.service.impl;

import cn.kgc.api.entity.RolesMenus;
import cn.kgc.api.mapper.RolesMenusMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.kgc.api.mapper.RolesMapper;
import cn.kgc.api.entity.Roles;
import cn.kgc.api.service.RolesService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author kgc
 */
@Slf4j
@Service("rolesService")
public class RolesServiceImpl extends ServiceImpl<RolesMapper, Roles> implements RolesService {
    @Resource
    private RolesMenusMapper rolesMenusMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteById(Integer id) {
        //根据角色id删除角色信息
        baseMapper.deleteById(id);
        //根据角色id删除 角色菜单关系信息
        LambdaQueryWrapper<RolesMenus> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(RolesMenus::getRid,id);
        rolesMenusMapper.delete(queryWrapper);
        return true;
    }
}